# It was quicker to do this than it was to read through the cmake
# documentation to find out how to set "-Os".
# I lie. I just hate CMake. ~oh look at me i'm being a Professional
# Software Engineer on source files all in a single directory for a
# single embedded target~
# --
# Chris Baird,, <chris.j.baird@gmail.com>

all:	satdata.h
	arm-none-eabi-gcc \
		-o build.elf \
		-Os -mcpu=cortex-m3 -mthumb -ffunction-sections -nostartfiles -std=gnu99 \
		-DSTM32F100C8 -DSTM32F10X_MD_VL -DUSE_STDPERIPH_DRIVER \
		-lstdc++ -Wl,--gc-sections -T arm-gcc-link.ld \
		-I cmsis -I cmsis_boot -I stm_lib/inc -I . \
		cmsis_boot/startup/startup_stm32f10x_md_vl.c cmsis_boot/system_stm32f10x.c \
		syscalls/syscalls.c \
		stm_lib/src/stm32f10x_adc.c stm_lib/src/stm32f10x_flash.c stm_lib/src/stm32f10x_rcc.c \
		stm_lib/src/stm32f10x_usart.c stm_lib/src/stm32f10x_tim.c stm_lib/src/stm32f10x_gpio.c \
		stm_lib/src/stm32f10x_spi.c stm_lib/src/stm32f10x_dma.c stm_lib/src/misc.c \
		init.c util.c delay.c radio.c ublox.c f_rtty.c satpredict.c morse.c main.c \
		-l m
	arm-none-eabi-objcopy -Obinary build.elf build.bin
	arm-none-eabi-size build.elf
	ls -l build.bin

flash:
	sudo st-flash --reset write build.bin 0x8000000

clean:
	rm -f build.elf build.bin predict.tle satdata.h *.o

satdata.h:
	bash updatetledata.sh
